<?php $this->load->helper('HTML');
echo link_tag('css/style2.css');
echo link_tag('images/favicon.ico','shortcut icon','image/x-icon');
?>
<div id="page1">
<?php $this->load->view('admin_views/header'); ?>
</head>
<div id="wrapper">
<script type="text/javascript">
    $(document).ready( function() {
	$("#rec1").dialog({
		autoOpen: false,
		modal: true,
		width: '300'
	});
    $("#rec2").dialog({
		autoOpen: false,
		modal: true,
		width: '300'
	});
    $("#intid_unit").autocomplete({
                    minLength: 2,
                    source:
                        function(req, add){
                        $.ajax({
                            url: "<?php echo base_url(); ?>penjualan/lookupUnit",
                            dataType: 'json',
                            type: 'POST',
                            data: req,
                            success:
                                function(data){
                                if(data.response =="true"){
                                    add(data.message);
                                }
                            },
                        });
                    },
                    focus:function(event,ui){var q=$(this).val();$(this).val()=q;},select:
                        function(event, ui) {
                        $("#result2").append(
                        "<input type='hidden' id='id_unit' name='id_unit' value='" + ui.item.id + "' size='10' />"
                    );
                    },
                });


        $("#strnama_dealer").autocomplete({
            minLength: 1,
            source:
                function(req, add){
                $.ajax({
                    url: "<?php echo base_url(); ?>penjualan/lookupUplineCalon",
                    dataType: 'json',
                    type: 'POST',
                    data: {
                     term: req.term,
                     state: $('#id_unit').val(),
                    },
                    success:
                        function(data){
                        if(data.response =="true"){
                            add(data.message);
                        }
                    },
                });
            },
            focus:function(event,ui){var q=$(this).val();$(this).val()=q;},select:
                function(event, ui) {
                        $("#result").append(
                        "<input type='text' align='top' id='strkode_dealer' name='strkode_dealer' value='" + ui.item.id + "'/><br><td><input type='text' id='strkode_upline' name='strkode_upline' value='" + ui.item.value2 + "'/></td>"
                    );
            },
        });

         $('#submit').click(function() {
            var form_data = {
                strkode_dealer : $('#strkode_dealer').val(),
                ajax : '1'
            };
            $.ajax({
                url: "<?php echo base_url(); ?>calon_manager/check_downline",
                type: 'POST',
                async : false,
                data: form_data,
                success: function(msg) {
                    $('#message').html(msg);
                }
            });
            return false;
        });
    });
</script>
<script type="text/javascript">
    

    function view_nota(id){
        $.ajax({
            type: 'POST',
            url: '<?php echo base_url(); ?>calon_manager/view_nota/'+id,
            data: $(this).serialize(),
            success: function(data) {
                $("#rec1").html(data);
                $('#rec1').dialog('option','width',1000);
                $('#rec1').dialog('option','title','Nota Detail');
                $('#rec1').dialog('option','buttons',{
                    "Close" : function(){
                        $('#rec1').dialog('close');
                    }	}).dialog('open').css('text-align','center');
            }
        });
    }

    function view_nota2(id){
        $.ajax({
            type: 'POST',
            url: '<?php echo base_url(); ?>calon_manager/view_nota/'+id,
            data: $(this).serialize(),
            success: function(data) {
                $("#rec2").html(data);
                $('#rec2').dialog('option','width',1000);
                $('#rec2').dialog('option','title','Nota Detail');
                $('#rec2').dialog('option','buttons',{
                    "Close" : function(){
                        $('#rec2').dialog('close');
                    }	}).dialog('open').css('text-align','center');
            }
        });
    }
</script>
</div>

<div id="page">
    <div id="page-bgtop">
        <div id="content">
            <div class="post">  <h2 class="title">SELEKSI CALON MANAGER</h2>

                <form method="post">
                    <table width="95%" border="0" cellpadding="0" cellspacing="0" id="data" align="center">

                        <tr>
                            <td  align='left' style='width:25%' >Pilih Unit</td>
                            <td><input type="text" name="textfield4" id="intid_unit" size="30" /><div id="result2"></div></td>
                        </tr>
                        <tr>
                            <td  align='left' style='width:25%' >Cari Nama Calon Manager</td>
                            <td><input type="text" name="strnama_dealer" id="strnama_dealer" size="60"/></td>
                        </tr>
                        <tr>
                            <td>&nbsp;No Kartu<br /><br />&nbsp;Upline :</td>
                            <td valign="top">&nbsp;<div id="result"></div></td>
                        </tr>
                        <tr>
                            <td><?php echo '<br />'.form_submit('submit','Proses','id="submit" class="button"')?></td>
                        </tr>
                    </table>
                </form>
                
                <div id="message"></div>
                
            </div>
        </div>

    </div>
    <div id="rec1" style="width:400px; height: 100px;"></div>
    <div id="rec2" style="width:400px; height: 100px;"></div>
    <!-- end #content -->
    <?php $this->load->view('admin_views/sidebar_manager'); ?><!-- end #sidebar -->
    <div style="clear: both;">&nbsp;</div>
</div>

<!-- end #page -->
<div id="footer-bgcontent">
    <?php $this->load->view('admin_views/footer'); ?></div>
<!-- end #footer -->
